package com.fiberhome.nas.core.model.entity

import kotlinx.serialization.Serializable

/**
 * 任务状态枚举类
 */
@Serializable
sealed class TaskStatus {
    @Serializable
    data object Uploading : TaskStatus()

    @Serializable
    data object Downloading : TaskStatus()

    @Serializable
    data object Paused : TaskStatus()

    @Serializable
    data object Waiting : TaskStatus()

    @Serializable
    data object Completed : TaskStatus()

    @Serializable
    data object Failed : TaskStatus()
}


@Serializable
class UploadTask {
    var id: String = ""
    var userId: String = ""
    var fileName: String = ""
    var fileSize: Long = 0
    var filePath: String = ""
    var fileType: String = ""
    var status: TaskStatus = TaskStatus.Waiting
    var uploadPath: String = ""
    var uploadedSize: Long = 0
    var totalSize: Long = 0
    var currentChunk: Int = 0
    var totalChunk: Int = 0
    var labelTip: String = ""   // 显示网速/失败原因/上传位置
    var favorite: Boolean? = null
    var duration: Long? = null
    var albumId: String? = null
    var mediaId: String = "0"   // 媒体文件ID

    /**
     * 创建当前任务的副本，可选择性地修改部分属性
     */
    fun copy(
        id: String = this.id,
        userId: String = this.userId,
        fileName: String = this.fileName,
        fileSize: Long = this.fileSize,
        filePath: String = this.filePath,
        fileType: String = this.fileType,
        status: TaskStatus = this.status,
        uploadPath: String = this.uploadPath,
        uploadedSize: Long = this.uploadedSize,
        totalSize: Long = this.totalSize,
        currentChunk: Int = this.currentChunk,
        totalChunk: Int = this.totalChunk,
        labelTip: String = this.labelTip,
        favorite: Boolean? = this.favorite,
        duration: Long? = this.duration,
        albumId: String? = this.albumId,
        mediaId: String = this.mediaId,
    ): UploadTask {
        val task = UploadTask()
        task.id = id
        task.userId = userId
        task.fileName = fileName
        task.fileSize = fileSize
        task.filePath = filePath
        task.fileType = fileType
        task.status = status
        task.uploadPath = uploadPath
        task.uploadedSize = uploadedSize
        task.totalSize = totalSize
        task.currentChunk = currentChunk
        task.totalChunk = totalChunk
        task.labelTip = labelTip
        task.favorite = favorite
        task.duration = duration
        task.albumId = albumId
        task.mediaId = mediaId
        return task
    }
}
